[filename].tsx (1159B)
1 import React from "react"; 2 import { InferGetStaticPropsType } from "next"; 3 import { Blocks } from "../components/blocks-renderer"; 4 import { useTina } from "tinacms/dist/react"; 5 import { client } from "../tina/__generated__/client"; 6 import Layout from "../components/layout/layout"; 7 8 export default function HomePage( 9 props: InferGetStaticPropsType<typeof getStaticProps> 10 ) { 11 const { data } = useTina(props); 12 13 return ( 14 <Layout rawData={data} data={data.global as any}> 15 <Blocks {...data.page} /> 16 </Layout> 17 ); 18 } 19 20 export const getStaticProps = async ({ params }) => { 21 const tinaProps = await client.queries.contentQuery({ 22 relativePath: `${params.filename}.md`, 23 }); 24 const props = { 25 ...tinaProps, 26 enableVisualEditing: process.env.VERCEL_ENV === "preview", 27 }; 28 return { 29 props: JSON.parse(JSON.stringify(props)) as typeof props, 30 }; 31 }; 32 33 export const getStaticPaths = async () => { 34 const pagesListData = await client.queries.pageConnection(); 35 return { 36 paths: pagesListData.data.pageConnection?.edges?.map((page) => ({ 37 params: { filename: page?.node?._sys.filename }, 38 })), 39 fallback: false, 40 }; 41 };